<template>
  <el-form :model="form" :disabled="disabled" label-width="auto" :rules="rules" ref="ruleFormRef">
    <el-form-item label="流程名称" prop="definitionNm">
      <el-input clearable v-model="form.definitionNm" placeholder="请输入流程名称" style="width: 50%;" />
    </el-form-item>
    <el-form-item label="流程业务类">
      <el-input clearable v-model="form.businessClass" placeholder="请输入流程业务类" style="width: 50%;" />
    </el-form-item>
    <el-form-item label="流程说明" prop="remark">
      <el-input type="textarea" v-model="form.remark" placeholder="请输入流程说明" style="width: 80%;" />
    </el-form-item>
    <el-form-item label="流程状态">
      <el-switch v-model="form.status" :active-value="'0'" :inactive-value="'1'" inline-prompt active-text="开启"
        inactive-text="关闭" />
    </el-form-item>
  </el-form>
</template>

<script setup>
import { ref, watch } from "vue";
import { ElMessage } from 'element-plus'

const props = defineProps({
  initData: {
    type: Object,
    default: () => { }
  },
  disabled: {
    type: Boolean,
    default: false
  }
})
watch(() => props.initData,
  (newInitData) => {
    const { wfNo, definitionNm, status, businessClass, remark } = newInitData
    form.value = { wfNo, definitionNm, status, businessClass, remark }
  }
)
const rules = ref({
  definitionNm: [
    { required: true, message: '请输入流程定义名称', trigger: 'blur' }
  ]
})
const ruleFormRef = ref()
const form = ref({ status: '0' })
const validateFlag = ref(false)
const validate = async () => {
  await ruleFormRef.value.validate(async (valid) => {
    if (valid) {
      validateFlag.value = true
    } else {
      validateFlag.value = false
      ElMessage.warning('请完善必输项信息！')
    }
  })
}

defineExpose({
  validate,
  validateFlag,
  form
});
</script>